from selenium.webdriver.common.by import By
from Base.Base import Base
import time

class Page(Base):
    # 定位器
    # 请登录定位元素
    login_loc = By.XPATH,'/html/body/div[2]/div/div[1]/div/a[1]'
    # 账号定位
    username_loc = By.ID,'userName'
    # 密码定位
    password_loc = By.NAME,'_pwd'
    # 登录按钮定位
    login_btn_loc = By.XPATH,'//input[@id="save" and @name="bi_Usuallogin"]'
    # 搜索按钮高级定位
    search_gaoji_loc = By.XPATH,'//input[@class="search-form" or @name="key"]'
    # 确认按钮定位
    sure_loc = By.CLASS_NAME,'bindSub'
    # 搜索输入框定位
    search_loc = By.XPATH,'/html/body/div[3]/div/div[2]/div[1]/form/input[1]'
    # 搜索按钮定位
    search_btn_loc = By.CSS_SELECTOR,'body > div.midHeader > div > div.headerSearch > div.searchHome > form > input.search-btn'
    # 选择商品定位
    sp_show_loc = By.XPATH,'/html/body/div[6]/div/div[2]/div[5]/ul/li[1]/div[2]/div[1]/a/img'
    # 加入购物车按钮定位
    add_card_loc = By.ID,'addToCartForDetail'

    # 封装定位方法
    # 点击请登录
    def login(self):
        self.click(self.login_loc)
    # 输入账号密码
    def username(self):
        self.send_keys(self.username_loc,'18238680385')
    def password(self):
        self.send_keys(self.password_loc,'123456Aa')
    # 点击登录按钮
    def login_btn(self):
        self.click(self.login_btn_loc)
    # 点击确认按钮
    def sure(self):
        self.click(self.sure_loc)
    # 搜索商品
    def search(self):
        self.key_enter(self.search_loc,'茅台')
    # 点击搜索按钮
    def search_btn(self):
        self.click(self.search_btn_loc)
    # 选择商品
    def sp_show(self):
        self.click(self.sp_show_loc)
    # 点击加入购物车
    def add_card(self):
        self.click(self.add_card_loc)

    # 业务逻辑
    def test_luojipage(self):
        self.login()
        self.username()
        self.password()
        # 强等输入验证码
        time.sleep(10)
        self.login_btn()
        self.sure()
        self.search()
        self.sp_show()
        # 切换页面
        self.new_window()
        self.add_card()

